#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
    setupUI();
    setupConnections();

}

void MainWindow::setupUI()
{

    setWindowTitle("智能农场");
    setWindowIcon(QIcon(":/icon/farm2.png"));
    // 创建主分割器
        mainSplitter = new QSplitter(Qt::Horizontal, this);
        setCentralWidget(mainSplitter);

        // 创建导航栏
        navigationBar = new NavigationBar(this);

        // 创建内容区域
        contentArea = new ContentArea(this);

        // 添加到分割器
        mainSplitter->addWidget(navigationBar);
        mainSplitter->addWidget(contentArea);

        // 设置分割比例
        //mainSplitter->setSizes({150, 650});
        mainSplitter->setSizes({500, 700});

        mainSplitter->setHandleWidth(1);
        mainSplitter->setStyleSheet("QSplitter::handle { background-color: #d0e8d0; }");

        // 设置窗口属性
        setWindowTitle("智能农场");
        //resize(800, 600);
        setFixedSize(1200, 600);
}
void MainWindow::setupConnections()
{
    // 连接导航栏信号到内容区域的槽函数
        connect(navigationBar, &NavigationBar::farmManagementSelected,
                contentArea, &ContentArea::showFarmManagement);

        connect(navigationBar, &NavigationBar::collaborationSelected,
                contentArea, &ContentArea::showCollaboration);

        connect(navigationBar, &NavigationBar::farmInfoSelected,
                contentArea, &ContentArea::showFarmInfo);

}

void MainWindow::setisAdmin(bool isAdmin)
{
    this->isAdmin=isAdmin;
    navigationBar->setisAdmin(isAdmin);
}

void MainWindow::setpermission(QString permission)
{
   // this->permission=permission;
    contentArea->setpermission(permission);
   // setupUI();

}
